package com.battcn;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;

/**
 * @author Levin
 */
@SpringBootApplication
public class Chapter6Application {

    private static final Logger logger = LoggerFactory.getLogger(Chapter6Application.class);

    public static void main(String[] args) {
        logger.info("Chapter6Application main start");
        SpringApplication.run(Chapter6Application.class, args);
        logger.info("Chapter6Application main end");
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> {
            logger.info("CommandLineRunner run start");
            String[] beanDefinitionNames = ctx.getBeanDefinitionNames();
            Arrays.stream(beanDefinitionNames).sorted().forEach(logger::info);
            logger.info("CommandLineRunner run end");
        };
    }

}
